package com.amoyt.project.domain.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 * 系统操作日志表（记录所有REST API操作）
 * </p>
 *
 * @author AmoyT
 * @since 2025-08-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_operation_log")
@Schema(description = "操作日志")
public class OperationLog implements Serializable {

    private static final long serialVersionUID = 1L;

     @TableId(value = "log_id", type = IdType.AUTO)
      @Schema(description = "日志ID（主键）")
      private Long logId;

      @Schema(description = "操作人ID（关联sys_user.id）")
      private String operatorId;

      @Schema(description = "操作人姓名（冗余存储，避免关联查询）")
      private String operatorName;

      @Schema(description = "业务名称")
      private String businessName;

      @Schema(description = "请求路径：/api/admin/user/add")
      private String requestPath;

      @Schema(description = "业务模块（归类API，如：用户管理、订单管理）")
      private String businessModule;


      @Schema(description = "操作类型：1-新增 2-修改 3-删除 4-查询 5-登录 6-登出 7-导入 8-导出 9-其他")
      private Integer operationType;

      @Schema(description = "方法参数（JSON格式，如：{'userId':1,'userName':'张三'}）")
      private String methodParams;

      @Schema(description = "操作结果：1-成功 0-失败")
      private Integer operationResult;

      @Schema(description = "结果数据（成功时存储关键返回值，如：{'userId':1}；失败时可存null）")
      private String resultData;

      @Schema(description = "操作IP地址（支持IPv4/IPv6）")
      private String ipAddress;

      @Schema(description = "客户端信息（如浏览器/APP版本，如：Mozilla/5.0...）")
      private String userAgent;

      @Schema(description = "错误信息（操作失败时存储异常栈信息，成功时为null）")
      private String errorMsg;

      @Schema(description = "操作时间（默认当前时间）")
      @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
      private LocalDateTime operationTime;

      @Schema(description = "逻辑删除")
      private Integer deleted;
}
